package stack_and_queue;

import java.util.Stack;

public class 验证图书取出顺序 {
    class Solution {
        public boolean validateBookSequences(int[] putIn, int[] takeOut) {
            if(putIn.equals(takeOut)) return true;
            if (putIn.length !=takeOut.length) return false;
           Stack<Integer> a = new Stack<>();
           int num = 0;
           for(int i : putIn){
               a.push(i);
               while (!a.isEmpty() && a.peek() == takeOut[num]){
                   a.pop();
                   num++;
               }
           }
           return a.isEmpty();
        }
    }
}
